<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Integer&lt;T&gt;</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Safe Numerics">
<link rel="up" href="concepts.html" title="Type Requirements">
<link rel="prev" href="numeric.html" title="Numeric&lt;T&gt;">
<link rel="next" href="promotion_policy.html" title="PromotionPolicy&lt;PP&gt;">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img href="index.html" height="164px" src="pre-boost.jpg" alt="Library Documentation Index"></td>
<td><h2>Safe Numerics</h2></td>
</tr></table>
<div class="spirit-nav">
<a accesskey="p" href="numeric.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="promotion_policy.html"><img src="images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="safe_numerics.integer"></a>Integer&lt;T&gt;</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="integer.html#idm56709020816">Description</a></span></dt>
<dt><span class="section"><a href="integer.html#idm56709014288">Refinement of</a></span></dt>
<dt><span class="section"><a href="integer.html#idm56709012784">Notation</a></span></dt>
<dt><span class="section"><a href="integer.html#idm56709002640">Valid Expressions</a></span></dt>
<dt><span class="section"><a href="integer.html#idm56702642064">Models</a></span></dt>
<dt><span class="section"><a href="integer.html#idm56702640336">Header</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm56709020816"></a>Description</h4></div></div></div>
<p>A type fulfills the requirements of an Integer if it has the
    properties of a integer.</p>
<p>More specifically, a type T is Integer if there exists a
    specialization of <code class="computeroutput">std::numeric_limits&lt;T&gt; for which
    std::numeric_limits&lt;T&gt;::is_integer</code> is equal to
    <code class="computeroutput">true</code>. See the documentation for standard library class
    <code class="computeroutput">numeric_limits</code>. The standard library includes such
    specializations for all built-in numeric types. Note that this concept is
    distinct from the C++ standard library type traits
    <code class="computeroutput">is_integral</code> and <code class="computeroutput">is_arithmetic</code>. These latter
    fulfill the requirements of the concept Numeric. But there are types which
    fulfill this concept for which <code class="computeroutput">is_arithmetic&lt;T&gt;::value ==
    false</code>. For example see <code class="computeroutput">safe&lt;int&gt;</code>.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm56709014288"></a>Refinement of</h4></div></div></div>
<p><a class="link" href="numeric.html" title="Numeric&lt;T&gt;">Numeric</a></p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm56709012784"></a>Notation</h4></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<tbody>
<tr>
<td align="left"><code class="computeroutput">T, U, V</code></td>
<td align="left">A type that is a model of an Integer type</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t, u</code></td>
<td align="left">An object of type modeling an Integer type</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">OS, IS</code></td>
<td align="left">A type that is a model of an output or input stream</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">os, is</code></td>
<td align="left">An object of a type modeling output or input stream</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm56709002640"></a>Valid Expressions</h4></div></div></div>
<p>In addition to the expressions defined in Integer, the following
    expression must be true. </p>
<div class="table">
<a name="idm56702693584"></a><p class="title"><b>Table 4. General</b></p>
<div class="table-contents"><table class="table" summary="General">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">Expression</th>
<th align="left">Value</th>
</tr></thead>
<tbody><tr>
<td align="left"><code class="computeroutput">std::numeric_limits&lt;T&gt;::is_integer</code></td>
<td align="left">true</td>
</tr></tbody>
</table></div>
</div>
<p><br class="table-break">Any or all of the following unary operators MAY be defined. Any
    such defined operators shall implement the semantics as described
    below</p>
<div class="table">
<a name="idm56702687104"></a><p class="title"><b>Table 5. Unary Operator</b></p>
<div class="table-contents"><table class="table" summary="Unary Operator">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">Expression</th>
<th align="left">Return Type</th>
<th align="left">Semantics</th>
</tr></thead>
<tbody><tr>
<td align="left"><code class="computeroutput">~t</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">bitwise complement</td>
</tr></tbody>
</table></div>
</div>
<p><br class="table-break">Any or all of the following binary operators MAY be defined. Any
    defined operators shall implement the semantics as described bellow</p>
<div class="table">
<a name="idm56702678704"></a><p class="title"><b>Table 6. Binary Operators</b></p>
<div class="table-contents"><table class="table" summary="Binary Operators">
<colgroup>
<col align="left">
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">Expression</th>
<th align="left">Return Type</th>
<th align="left">Semantics</th>
</tr></thead>
<tbody>
<tr>
<td align="left"><code class="computeroutput">t % u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">t modulus u. t can be a Numeric type.</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t &lt;&lt; u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">shift t left u bits</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t &gt;&gt; u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">shift t right by u bits</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t &amp; u</code></td>
<td align="left"><code class="computeroutput">V</code></td>
<td align="left">and of t and u padded out to max # bits in t, u</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t | u</code></td>
<td align="left"><code class="computeroutput">V</code></td>
<td align="left">or of t and u padded out to max # bits in t, u</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t ^ u</code></td>
<td align="left"><code class="computeroutput">V</code></td>
<td align="left">exclusive or of t and u padded out to max # bits in t,
              u</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t &lt;&lt;= u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">left shift the value of t by u bits</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t &gt;&gt;= u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">right shift the value of t by u bits</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t &amp;= u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">and the value of t with u and assign to t</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t |= u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">or the value of t with u and assign to t</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t ^= u</code></td>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left">exclusive or the value of t with u and assign to
              t</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">os &lt;&lt; t</code></td>
<td align="left"><code class="computeroutput"><code class="computeroutput">OS &amp;</code></code></td>
<td align="left">write contents of t to output stream</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">is &gt;&gt; t</code></td>
<td align="left"><code class="computeroutput"><code class="computeroutput">IS &amp;</code></code></td>
<td align="left">read contents of an input stream into t</td>
</tr>
</tbody>
</table></div>
</div>
<p><br class="table-break"></p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm56702642064"></a>Models</h4></div></div></div>
<p><code class="computeroutput">int, safe&lt;int&gt;, safe_unsigned_range&lt;0, 11&gt;,
    checked_result&lt;int&gt; etc.</code></p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm56702640336"></a>Header</h4></div></div></div>
<p><a href="../../include/boost/safe_numerics/concept/numeric.hpp" target="_top"><code class="computeroutput">#include
    &lt;boost/safe_numerics/concepts/integer.hpp&gt; </code></a></p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2012-2018 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
      Software License</a></p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="numeric.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="promotion_policy.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>
